package com.xhtranslate.service.youdao.controller;

import com.xhtranslate.common.dto.ImageOcrDTO;
import com.xhtranslate.common.vo.ResponseVO;
import com.xhtranslate.service.youdao.service.YoudaoOcrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Map;

/**
 * @author liuxuhuang
 * @version 1.0
 * @package com.xhtranslate.service.youdao.controller
 * @date 2022/11/17 16:56:49
 * @description 有道Ocr请求接口
 */
@RestController
@Api(value = "有道OCR请求接口", tags = "有道OCR请求接口")
@RequestMapping(value = "youdaoOcr")
@Slf4j
public class YoudaoOcrController {
    @Autowired
    private YoudaoOcrService youdaoOcrService;

    @PostMapping(value = "ocr")
    @ApiOperation(value = "有道文字识别")
    public ResponseVO youdaoOCR(ImageOcrDTO dto) throws IOException {
        log.warn("有道文字识别：" + dto);
        Map<String, String> map = youdaoOcrService.ocrImg(dto.getFile());
        return map.get("errorCode").equals("0") ? ResponseVO.succ(map.get("data")) : ResponseVO.exception(map.get("msg"));
    }
}
